package org.yenn.pattern.aliyun.structural.filtercriteria;

import org.junit.Test;
import org.yenn.pattern.aliyun.structural.filtercriteria.impl.*;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

/**
 * 步骤4
 * 使用不同的标准（Criteria）和它们的结合来过滤 Person 对象的列表。
 */
public class CriteriaPatternDemo {
    /**
     * 步骤 5
     * 验证输出。
     *
     * Males:
     * [Person(name=Robert, gender=Male, maritalStatus=Single), Person(name=John, gender=Male, maritalStatus=Married), Person(name=Mike, gender=Male, maritalStatus=Single), Person(name=Bobby, gender=Male, maritalStatus=Single)]
     *
     * Females:
     * [Person(name=Laura, gender=Female, maritalStatus=Married), Person(name=Diana, gender=Female, maritalStatus=Single)]
     *
     * Single Males:
     * []
     *
     * Single Or Females:
     * [Person(name=Laura, gender=Female, maritalStatus=Married), Person(name=Diana, gender=Female, maritalStatus=Single)]
     */
    @Test
    public void meetCriteria() {
        List<Person> persons = new ArrayList();

        persons.add(new Person("Robert", "Male", "Single"));
        persons.add(new Person("John", "Male", "Married"));
        persons.add(new Person("Laura", "Female", "Married"));
        persons.add(new Person("Diana", "Female", "Single"));
        persons.add(new Person("Mike", "Male", "Single"));
        persons.add(new Person("Bobby", "Male", "Single"));

        Criteria male = new CriteriaMale();
        Criteria female = new CriteriaFemale();
        Criteria single = new CriteriaSingle();
        Criteria singleMale = new AndCriteria(single, male);
        Criteria singleOrFemale = new OrCriteria(single, female);

        System.out.println("Males: ");
        System.out.println(male.meetCriteria(persons));

        System.out.println("\nFemales: ");
        System.out.println(female.meetCriteria(persons));

        System.out.println("\nSingle Males: ");
        System.out.println(singleMale.meetCriteria(persons));

        System.out.println("\nSingle Or Females: ");
        System.out.println(singleOrFemale.meetCriteria(persons));
    }


}